﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KF.DHLBL
{
    public class Customer : BLBase
    {
        public String Add(KF.DHLModel.BaseInfo.Customer customer)
        {
            var c = (from info in CUSTOMERS_ALL
                     where info.Code == customer.Code
                     select info);
            if (c != null && c.Count() > 0)
            {
                return "存在相同的Code："+customer.Code + "!";
            }
            try
            {
                KF.DHL.DAL.Customer customerDal = new KF.DHL.DAL.Customer();
                customerDal.Add(customer);
                CUSTOMERS_ALL = customerDal.GetALL();

                return "0";
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public List<KF.DHLModel.BaseInfo.Customer> GetALL()
        {
            return CUSTOMERS_ALL;
        }

        public String Update(KF.DHLModel.BaseInfo.Customer customer)
        {
            var c = (from info in CUSTOMERS_ALL
                     where info.Code == customer.Code
                     select info);
            if (c == null && c.Count() == 0)
            {
                return "不存在相应的客户(Code：" + customer.Code + ")!";
            }
            try
            {
                KF.DHL.DAL.Customer customerDal = new KF.DHL.DAL.Customer();
                customerDal.Update(customer);
                CUSTOMERS_ALL = customerDal.GetALL();

                return "0";
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
